<?php

namespace app\api\controller;

use app\common\controller\Api;
use app\api\model\Coupon as CouponM;

class Coupon extends Api
{
    protected $noNeedLogin = ['ListData'];
    protected $noNeedRight = ['*'];

    /**
     * 券列表
     * @return void
     * @throws \think\exception\DbException
     */
    public function ListData()
    {
       $CouponM = new CouponM();
       $where['start_time']=['<',time()];
       $where['end_time']=['>',time()];
       $where['status']=1;
       $where['show_switch']=1;
       $list=$CouponM->where($where)->paginate(10);
       $this->success('',$list);
    }
/**
     * 领取优惠券
     * @return void
     */
    public function receive()
    {
        $param= $this->request->param();
        $CouponM = new CouponM();
        $user= $this->auth;
        if($param['id']!="all"){
            $where['id']=['in', $param['id']];
        }
        $where['start_time']=['<',time()];
        $where['end_time']=['>',time()];
        $where['status']=1;
        $where['show_switch']=1;
        $list=$CouponM->where($where)->select();
        foreach ($list as $k=>$v){
            //首先要判断是否领取过了//领取过的 要 跳过

        }
        $this->success('');
    }

}
